<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
/**
 * 订单模型
 */
class Order_Admin_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	
	/**
	 * 管理员使用，获取所有 获取order_log的列表
	 */
	public function order_log_list_all($page,$perpage) {
		$sql = "SELECT * ";
		$sql .= "FROM `pc_ddth_order_log` ";
		$sql .= " ORDER BY create_time DESC, id";
		$sql .= " limit ".$perpage*($page-1).','.$perpage;
		$query = $this->db->query ( $sql );
	
		return $query->result_array ();
	}
	
	/**
	 * 管理员使用，获取所有的count, 获取order_log的列表
	 */
	public function order_log_list_all_count() {

		return $this->db->count_all_results('pc_ddth_order_log');
	}
	
	/**
	 * 管理员使用，获取所有offer 获取order_log的列表
	 */
		/**public function offer_order_log_list_all($page,$perpage) {
		$sql = "SELECT ";
		$sql .= "oo.`create_time` AS sq_time,";
		$sql .= "ol.id,";
		$sql .= "ol.money,";
		$sql .= "ol.user_id,";
		$sql .= "ol.bianhao,";
		$sql .= "ol.dakuan,";
		$sql .= "ol.shoukuan,";
		$sql .= "ol.accept_order_id,";
		$sql .= "ol.day_num,";
		//$sql .= "ol.lilv,";
		$sql .= "ol.out_day_num,";
		$sql .= "ol.`create_time` AS hz_time ,";
		$sql .= "oo.`user_id`,";
		$sql .= "dakuan,";
		$sql .= "img_url, ";
		$sql .= "user_name, ";
		$sql .= "user_account, ";
		$sql .= "zfb_account, ";
		$sql .= "bank_name, ";
		$sql .= "bank_card, ";
		$sql .= "wx_id, ";
		$sql .= "mobile ";
		$sql .= "FROM `pc_ddth_accept_order` AS ao,`pc_ddth_order_log` AS ol,`pc_ddth_offer_order` AS oo ,pc_ddth_user AS u ";
		$sql .= "WHERE ol.`accept_order_id` = ao.`id` ";
		$sql .= "AND ol.`offer_order_id` = oo.`id` ";
		$sql .= "AND oo.user_id = u.`id` ";
		$sql .= " ORDER BY ol.id";
		$sql .= " limit ".$perpage*($page-1).','.$perpage;
		// echo $sql;
		$query = $this->db->query ( $sql );
		
		return $query->result_array ();
	}
	*/
	public function offer_order_log_list_all($page,$perpage) {
		$sql = "SELECT * ";
		$sql .= "FROM `pc_ddth_offer_order` ";

		$sql .= " ORDER BY status, yxflag desc ,id desc ";
		$sql .= " limit ".$perpage*($page-1).','.$perpage;
		// echo $sql;
		$query = $this->db->query ( $sql );
		
		return $query->result_array ();
	}
	/**
	 * 管理员使用，获取所有offer的count, 获取order_log的列表
	 */
	/**public function offer_order_log_list_all_count() {
		$sql = "SELECT ";
		$sql .= "oo.`create_time` AS sq_time,";
		$sql .= "ol.id,";
		$sql .= "ol.money,";
		$sql .= "ol.day_num,";
		//$sql .= "ol.lilv,";
		$sql .= "ol.out_day_num,";
		$sql .= "ol.`create_time` AS hz_time ,";
		$sql .= "oo.`user_id`,";
		$sql .= "dakuan,";
		$sql .= "img_url, ";
		$sql .= "user_name, ";
		$sql .= "user_account, ";
		$sql .= "zfb_account, ";
		$sql .= "bank_name, ";
		$sql .= "bank_card, ";
		$sql .= "wx_id, ";
		$sql .= "mobile ";
		$sql .= "FROM `pc_ddth_accept_order` AS ao,`pc_ddth_order_log` AS ol,`pc_ddth_offer_order` AS oo ,pc_ddth_user AS u ";
		$sql .= "WHERE ol.`accept_order_id` = ao.`id` ";
		$sql .= "AND ol.`offer_order_id` = oo.`id` ";
		$sql .= "AND oo.user_id = u.`id` ";
		$sql .= " ORDER BY ol.id";
		// echo $sql;
		$query = $this->db->query ( $sql );
	
		//return $query->result_array ();
		
		return $this->db->count_all_results('pc_ddth_accept_order');
	}
	***/
	public function offer_order_log_list_all_count() {
		
		return $this->db->count_all_results('pc_ddth_offer_order');
	}
	/**
	 * 管理员获取所有order_log的列表
	 */
	/**public function accept_order_log_list_all($page,$perpage) {
		$sql = "SELECT ";
		$sql .= "ao.`create_time` AS sq_time,";
		$sql .= "ao.`order_type`,";
		$sql .= "ol.id,";
		$sql .= "ol.money,";
		$sql .= "ol.bianhao,";
		$sql .= "ol.accept_order_id,";
		$sql .= "ol.`create_time` AS pp_time ,";
		$sql .= "oo.`user_id`,";
		$sql .= "dakuan,dakuan_time,";
		$sql .= "shoukuan,";
		$sql .= "img_url, ";
		$sql .= "user_name, ";
		$sql .= "user_account, ";
		$sql .= "mobile ";
		$sql .= "FROM `pc_ddth_accept_order` AS ao,`pc_ddth_order_log` AS ol,`pc_ddth_offer_order` AS oo ,pc_ddth_user AS u ";
		$sql .= "WHERE ol.`accept_order_id` = ao.`id` ";
		$sql .= "AND ol.`offer_order_id` = oo.`id` ";
		$sql .= "AND oo.user_id = u.`id` ";
		$sql .= " ORDER BY ol.id";
		$sql .= " limit ".$perpage*($page-1).','.$perpage;
		$query = $this->db->query ( $sql );
		
		return $query->result_array ();
	}*/
	
	public function accept_order_log_list_all($page,$perpage) {
		$sql = "SELECT * ";
		$sql .= "FROM `pc_ddth_accept_order` ";
		$sql .= " ORDER BY status, yxflag desc ,id desc ";
		$sql .= " limit ".$perpage*($page-1).','.$perpage;
		$query = $this->db->query ( $sql );
		
		return $query->result_array ();
	}
	
	public function update_accept_yxflag($val,$id)
	{
		$data['yxflag'] = $val;

		$result = $this->db->update('pc_ddth_accept_order', $data,array('id' =>$id));

		return $result;
	}
	public function update_offer_yxflag($val,$id)
	{
		$data['yxflag'] = $val;

		$result = $this->db->update('pc_ddth_offer_order', $data,array('id' =>$id));

		return $result;
	}
	/**
	 * 管理员获取所有order_log的列表
	 */
	public function accept_order_log_list_all_count() {
		return $this->db->count_all_results('pc_ddth_accept_order');;
	}
	
}
